<?php

function smarty_function_print2($params){	
	global $setupdata, $mysqlclass, $translate, $treeclass;
	$lang=$_SESSION['lang'];
	$strname=addslashes($params['lt']);		
	$lang_array1 = $treeclass->gettreetypes('lang');	
	/* create table if no exist */
	$query="
	CREATE TABLE IF NOT EXISTS `".$setupdata['table_prefix']."print2` (
	  `id` int(11) NOT NULL auto_increment,
	  `lang` varchar(5) NOT NULL default '',
	  `name` tinytext NOT NULL,
	  `value` tinytext NOT NULL,
	  UNIQUE KEY `id` (`id`)
	) ENGINE=MyISAM
	";
	$mysqlclass->mysql_my_query($query, __LINE__, __FILE__);
	/* /create table if no exist */	
	if (strlen($lang)<1 || strlen($strname)<1) return;	
 	$sql = $mysqlclass->mysql_my_query("SELECT * FROM `".$setupdata['table_prefix']."print2` WHERE MD5(`name`)='".md5($strname)."'", __LINE__, __FILE__);
	if (mysql_num_rows($sql)>0){
		while ($row = mysql_fetch_assoc($sql)) {$stored_vars[$row['lang']]=trim($row['value']);}		
		mysql_free_result($sql);
		if (isset($stored_vars[$lang]) && strlen($stored_vars[$lang])>0){
			echo $stored_vars[$lang];
		} elseif (isset($stored_vars[$lang]) && strlen($stored_vars[$lang])<1)  {
			echo $stored_vars['lt'];						
		} else {			
			$query="INSERT INTO `".$setupdata['table_prefix']."print2` (`lang`,`name`,`value`) VALUES ('".$lang."','".$strname."','')";
		}
	} else {
		foreach ($lang_array1 as $value) {
			$tmpVal=strtolower($value['name']);
			
			if (isset($params[$tmpVal])) $strvalue=$params[$tmpVal];
			else $strvalue='';
			
			$query="INSERT INTO `".$setupdata['table_prefix']."print2` (`lang`,`name`,`value`) VALUES ('".strtolower($value['name'])."','".$strname."','".$strvalue."')";
			$mysqlclass->mysql_my_query($query, __LINE__, __FILE__);
		}
		echo $strname;
	}
}

?>
